﻿Imports System.IO
Imports System.Data.SqlClient
Imports Microsoft.Win32
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Threading
Imports DevExpress.XtraBars.Alerter
Imports System.Runtime.InteropServices
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Nodes
Imports DevExpress.Utils.Menu
Imports DevExpress.XtraBars
Imports System.Xml

Public Class mdiMain
    Dim mblnLogOut As Boolean = False
    Dim mblnCancelled As Boolean = False
    Dim alertActivate As Boolean = False
    Dim mblnInitial As Boolean = True



    <DllImport("user32.dll")> _
  Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("shell32.dll")> _
    Shared Function SHAppBarMessage(ByVal dwMessage As UInteger, ByVal pAppBarData As IntPtr) As UIntPtr
    End Function

    <StructLayout(LayoutKind.Sequential)> _
    Private Structure AppBarData
        Public cbSize As Integer
        Public hWnd As IntPtr
        Public uCallbackMessage As UInteger
        Public uEdge As UInteger
        Public rc As Rect
        Public lParam As IntPtr
    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Private Structure Rect
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
    End Structure

    Private Sub mdiMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Try
            If gblnLockPermission = True Then
                Dim frmTmpUnlockApplication As New frmUnlockApplication
                frmTmpUnlockApplication.ShowInTaskbar = False
                Dim result As DialogResult = frmTmpUnlockApplication.ShowDialog

                If result = Windows.Forms.DialogResult.Yes Then
                    If gblnIsRefreshed = False Then
                        Call frmShowAppointment.PopulateScheduler()
                    End If
                    gblnLockPermission = False
                    Me.WindowState = FormWindowState.Maximized
                Else
                    'Me.Close()
                    Me.WindowState = FormWindowState.Minimized
                End If
            Else
                If gblnIsRefreshed = False Then
                    '  Call frmShowAppointment.PopulateScheduler()
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub mdiMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        gconWebPlusMed.Dispose()
    End Sub

    Private Sub mdiMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If mblnLogOut = False Then
            frmUtilityProcessing.Dispose()
            Me.Dispose()
        Else
            mblnLogOut = False
        End If
        If gstrUserName <> "p" Then
            Call UpdateTable("utility_user_login_details", "logout_time='" & gdtCurrentDate & "'", "record_id=" & glngLoginHistoryID)
        End If
    End Sub

    Private Sub mdiMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Me.Icon = System.Drawing.Icon.FromHandle(CType(imgMDIForm.Images(97), Bitmap).GetHicon())
        If gbIsLicensed = True Then mnuRegister.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
        'DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Blue")
        'BarButtonItem11.
        mnuUserLogin.Caption = "User Loged In - " & gstrUserName
        mnuCurrentDate.Caption = Now.ToShortDateString
        mnuCurrentTime.Caption = Now.ToShortTimeString
        mnuCapsLock.Caption = "CAPS LOCK: " & IIf(My.Computer.Keyboard.CapsLock = True, "ON", "OFF")
        mnuNumLock.Caption = "NUM LOCK: " & IIf(My.Computer.Keyboard.NumLock = True, "ON", "OFF")
        Me.Text = gstrSoftware & "    [ " & gstrDataSource & "   " & IIf(gblnNetwork = True, "Remote Server", "Local Server") & " ]"
        Call SetPermission()
        If Array.IndexOf(gstrAPForms, "frmUtilityLockRecords").ToString >= 0 Then gblnLockPermission = True

        If gstrUserName <> "p" Then
            Call DisableMenu()
        End If
        gblnLockPermission = False
        gblnTimerTick = True
        Dim frmTempShowAppointment As New frmShowAppointment
        With frmTempShowAppointment
            .TopLevel = False
            .MdiParent = Me
            .Dock = DockStyle.Fill
            .FormBorderStyle = Windows.Forms.FormBorderStyle.None
            .SendToBack()
            .Show()
            .Location = New Point(0, 0)
            .StartPosition = FormStartPosition.CenterScreen
            objAppointments = frmTempShowAppointment
        End With
    End Sub

    Private Sub DisableMenu()
        Try
            'Patients and Visits
            If Array.IndexOf(gstrAPForms, "frmPatientInfo", 0) >= 0 Then mnuPatientInformation.Enabled = True Else mnuPatientInformation.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPatientSearch", 0) >= 0 Then
                mnuSearchPatient.Enabled = True
                mnuSearch.Enabled = True
            Else
                mnuSearchPatient.Enabled = False
                mnuSearch.Enabled = False
            End If

            If Array.IndexOf(gstrAPForms, "frmRegistrationWizard", 0) >= 0 Then
                mnuRegistrationWizard.Enabled = True
                mnuRegisterPatient.Enabled = True
            Else
                mnuRegistrationWizard.Enabled = False
                mnuRegisterPatient.Enabled = False
            End If
            If Array.IndexOf(gstrAPForms, "frmNurseNote", 0) >= 0 Then
                mnuNursesNote.Enabled = True
                If gintUserLevelId = 3 Then
                    mnuAddNotes.Enabled = True
                End If
            Else
                mnuNursesNote.Enabled = False
                mnuAddNotes.Enabled = False
            End If

            If Array.IndexOf(gstrAPForms, "frmDoctorsNote", 0) >= 0 Then
                mnuDoctorsNote.Enabled = True
                If gintUserLevelId = 1 Or gintUserLevelId = 2 Then
                    mnuAddNotes.Enabled = True
                End If
            Else
                mnuDoctorsNote.Enabled = False
                mnuAddNotes.Enabled = False
            End If

            If Array.IndexOf(gstrAPForms, "frmPatientStatus", 0) >= 0 Then mnuChangePatientStatus.Enabled = True Else mnuChangePatientStatus.Enabled = False

            'Billing
            If Array.IndexOf(gstrAPForms, "frmChargeAndPayment", 0) >= 0 Then mnuChargesPayment.Enabled = True Else mnuChargesPayment.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptInvoice", 0) >= 0 Then mnuInvoiceReport.Enabled = True Else mnuInvoiceReport.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptReciept", 0) >= 0 Then mnuReceiptReport.Enabled = True Else mnuReceiptReport.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptOutstandingBalance", 0) >= 0 Then mnuOutstandingBalanceReport.Enabled = True Else mnuOutstandingBalanceReport.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPatientStatement", 0) >= 0 Then mnuPatientStatement.Enabled = True Else mnuPatientStatement.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmClearCheck", 0) >= 0 Then mnuUpdateCheckStatus.Enabled = True Else mnuUpdateCheckStatus.Enabled = False

            'Reports
            If Array.IndexOf(gstrAPForms, "frmVisitSummary", 0) >= 0 Then mnuVisitSummary.Enabled = True Else mnuVisitSummary.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmVisitDetails", 0) >= 0 Then mnuVisitDetails.Enabled = True Else mnuVisitDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptPatientProfile", 0) >= 0 Then mnuPatientProfile.Enabled = True Else mnuPatientProfile.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmBloodPressureGraph", 0) >= 0 Then mnuBloodPressureGraph.Enabled = True Else mnuBloodPressureGraph.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmLengthForAge", 0) >= 0 Then mnuLengthForAge.Enabled = True Else mnuLengthForAge.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmWeightForAge", 0) >= 0 Then mnuWeightFor36Age.Enabled = True Else mnuWeightFor36Age.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmWeightForLength", 0) >= 0 Then mnuWeightForLength.Enabled = True Else mnuWeightForLength.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmBMIForAge", 0) >= 0 Then mnuBMIForAge.Enabled = True Else mnuBMIForAge.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmHeadCircumference", 0) >= 0 Then mnuHeadCirAge.Enabled = True Else mnuHeadCirAge.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmDiagnosisFrequency", 0) >= 0 Then mnuDiagnosisFrequency.Enabled = True Else mnuDiagnosisFrequency.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPracticeStatisticCharts", 0) >= 0 Then mnuDrugUseFrequency.Enabled = True Else mnuDrugUseFrequency.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmNoOfPatientSeen", 0) >= 0 Then mnuNoofPatientsSeen.Enabled = True Else mnuNoofPatientsSeen.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmCauseOfDeathStatistics", 0) >= 0 Then mnuCauseofDeath.Enabled = True Else mnuCauseofDeath.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmDaysPatient", 0) >= 0 Then mnuDaysPatients.Enabled = True Else mnuDaysPatients.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmWaitingPatient", 0) >= 0 Then mnuWaitingPatients.Enabled = True Else mnuWaitingPatients.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmAddressBook", 0) >= 0 Then mnuAddressBook.Enabled = True Else mnuAddressBook.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRevenueByDate", 0) >= 0 Then mnuRevenueByDate.Enabled = True Else mnuRevenueByDate.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRevenueByMonth", 0) >= 0 Then mnuRevenueByMonth.Enabled = True Else mnuRevenueByMonth.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRevenueByDiagnosis", 0) >= 0 Then mnuRevenueByDiagnosis.Enabled = True Else mnuRevenueByDiagnosis.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRevenueByDemographics", 0) >= 0 Then mnuRevenueByDemographics.Enabled = True Else mnuRevenueByDemographics.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmSelectReport", 0) >= 0 Then mnuReportsIcon.Enabled = True Else mnuReportsIcon.Enabled = False

            'Inventory
            If Array.IndexOf(gstrAPForms, "frmVendor", 0) >= 0 Then mnuVendorInformation.Enabled = True Else mnuVendorInformation.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmManufacturer", 0) >= 0 Then mnuManufacturerInformation.Enabled = True Else mnuManufacturerInformation.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmMasterInventoryUnits", 0) >= 0 Then mnuUnitDetails.Enabled = True Else mnuUnitDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmMasterInventoryCategory", 0) >= 0 Then mnuCategoryDetails.Enabled = True Else mnuCategoryDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmItemDetails", 0) >= 0 Then mnuItemDetails.Enabled = True Else mnuItemDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPurchaseOrder", 0) >= 0 Then mnuPurchaseOrder.Enabled = True Else mnuPurchaseOrder.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPurchase", 0) >= 0 Then mnuPurchaseDetails.Enabled = True Else mnuPurchaseDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmInventoryAdjustment", 0) >= 0 Then mnuInventoryAdjustment.Enabled = True Else mnuInventoryAdjustment.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmFixedAssets", 0) >= 0 Then mnuFixedAssets.Enabled = True Else mnuFixedAssets.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmFixedAssetCategory", 0) >= 0 Then mnuFixedAssetCategory.Enabled = True Else mnuFixedAssetCategory.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmFixedAssetsInventory", 0) >= 0 Then mnuRptFixedAssetsInventory.Enabled = True Else mnuRptFixedAssetsInventory.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmFixedAssetsListing", 0) >= 0 Then mnuRptFixedAssetListing.Enabled = True Else mnuRptFixedAssetListing.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptVendorListing", 0) >= 0 Then mnuRptVendorListing.Enabled = True Else mnuRptVendorListing.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptItemsReorder", 0) >= 0 Then mnuRptItemstobeReorder.Enabled = True Else mnuRptItemstobeReorder.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptOnHandInventory", 0) >= 0 Then mnuRptOnHandInventory.Enabled = True Else mnuRptOnHandInventory.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmRptInventoryActivityReport", 0) >= 0 Then mnuRptInventoryActivity.Enabled = True Else mnuRptInventoryActivity.Enabled = False


            'Tools
            If Array.IndexOf(gstrAPForms, "frmUtilityUserAccess", 0) >= 0 Then mnuUserDetails.Enabled = True Else mnuUserDetails.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmUtilityChangePassword", 0) >= 0 Then mnuChangePassword.Enabled = True Else mnuChangePassword.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmUtilityBackupRestore", 0) >= 0 Then mnuBackupRestore.Enabled = True Else mnuBackupRestore.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmUtilityRegistrySettings", 0) >= 0 Then mnuServerSettings.Enabled = True Else mnuServerSettings.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmUtilitySettings", 0) >= 0 Then mnuDatabaseSettings.Enabled = True Else mnuDatabaseSettings.Enabled = False

            If Array.IndexOf(gstrAPForms, "frmToolsLookUp", 0) >= 0 Then mnuLookupValues.Enabled = True Else mnuLookupValues.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmMedicalVocabulary", 0) >= 0 Then mnuMedicalVocabulary.Enabled = True Else mnuMedicalVocabulary.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmProcedures", 0) >= 0 Then mnuProcedures.Enabled = True Else mnuProcedures.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmSpecialist", 0) >= 0 Then mnuSpecialistInformation.Enabled = True Else mnuSpecialistInformation.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmPracticeInformation", 0) >= 0 Then mnuPracticeInformation.Enabled = True Else mnuPracticeInformation.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmSetAppointmentTime", 0) >= 0 Then mnuSetAppointmentDayWise.Enabled = True Else mnuSetAppointmentDayWise.Enabled = False
            If Array.IndexOf(gstrAPForms, "frmMessages", 0) >= 0 Then
                mnuInstantMessaging.Enabled = True
                mnuMessaging.Enabled = True
            Else
                mnuInstantMessaging.Enabled = False
                mnuMessaging.Enabled = False
            End If
            If Array.IndexOf(gstrAPForms, "frmAppointmentEntry", 0) >= 0 Then
                mnuTbAppointments.Enabled = True
            Else
                mnuTbAppointments.Enabled = False
            End If
            'frmAppointmentEntry
            If Array.IndexOf(gstrAPForms, "frmTask", 0) >= 0 Then
                mnuTasks.Enabled = True
                mnuTask1.Enabled = True
            Else
                mnuTasks.Enabled = False
                mnuTask1.Enabled = False
            End If
            If Array.IndexOf(gstrAPForms, "frmDrugDetails", 0) >= 0 Then
                mnuDrugInformation.Enabled = True
                mnuDrugs.Enabled = True
            Else
                mnuDrugInformation.Enabled = False
                mnuDrugs.Enabled = False
            End If

            If Array.IndexOf(gstrAPForms, "frmImportDrug", 0) >= 0 Then mnuImportDrug.Enabled = True Else mnuImportDrug.Enabled = False

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub mnuRegister_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRegister.ItemClick
        Dim frmTempREG As New frmUtilityRegister
        With frmTempREG
            .mblnCalledInner = True
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempREG = Nothing
            GC.Collect()
        End With
        If gbIsLicensed = True Then mnuRegister.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
    End Sub

    Private Sub mnuAbout_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuAbout.ItemClick
        Dim frmTempABOUT As New frmUtilityAbout
        With frmTempABOUT
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempABOUT = Nothing
            GC.Collect()
        End With
    End Sub

    Private Sub mnuServerSettings_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuServerSettings.ItemClick
        Dim frmTempREGSETT As New frmUtilityRegistrySettings
        With frmTempREGSETT
            .mblnCalledInner = True
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempREGSETT = Nothing
            GC.Collect()
        End With
    End Sub

    Private Sub mnuChangePassword_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuChangePassword.ItemClick
        Dim frmTempChangePassword As New frmUtilityChangePassword
        With frmTempChangePassword
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempChangePassword = Nothing
            GC.Collect()
        End With
    End Sub

    Private Sub mnuDatabaseSettings_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDatabaseSettings.ItemClick
        Dim frmTempSettings As New frmUtilitySettings
        With frmTempSettings
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempSettings = Nothing
            GC.Collect()
        End With
    End Sub

    Private Sub mnuBackupRestore_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuBackupRestore.ItemClick
        If isLoaded("frmUtilityBackupRestore", "") Then Exit Sub
        Dim frmTempBackupRestore As New frmUtilityBackupRestore
        LoadCursor(Me)
        With frmTempBackupRestore
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuNewVersion_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        Dim frmTempVersionControl As New frmUtilityVersionControl
        With frmTempVersionControl
            .ShowInTaskbar = False
            .ShowDialog()
            .Dispose()
            frmTempVersionControl = Nothing
            GC.Collect()
        End With
    End Sub

    Private Sub mnuUserDetails_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuUserDetails.ItemClick
        If isLoaded("frmUtilityUserAccess", "") = True Then Exit Sub
        Dim frmTempUserAccess As New frmUtilityUserAccess
        frmTempUserAccess.MdiParent = Me
        frmTempUserAccess.Show()
    End Sub

    Private Sub SetPermission()
        Try
            Dim dsPermission As DataSet
            Dim row As DataRow
            Dim intCtr As Integer

            dsPermission = FillDataSet("Select * from utility_user_access Where user_pk=" & gintUserID)

            ReDim gstrAccessPermission(dsPermission.Tables(0).Rows.Count - 1, 3)
            ReDim gstrAPForms(dsPermission.Tables(0).Rows.Count - 1)

            For Each row In dsPermission.Tables(0).Rows
                gstrAPForms(intCtr) = row.Item("form_name")
                If gstrUserName <> "p" Then
                    gstrAccessPermission(intCtr, 0) = row.Item("form_name")
                    gstrAccessPermission(intCtr, 1) = row.Item("add_lev")
                    gstrAccessPermission(intCtr, 2) = row.Item("edit_lev")
                    gstrAccessPermission(intCtr, 3) = row.Item("delete_lev")
                Else
                    gstrAccessPermission(intCtr, 0) = row.Item("form_name")
                    gstrAccessPermission(intCtr, 1) = True
                    gstrAccessPermission(intCtr, 2) = True
                    gstrAccessPermission(intCtr, 3) = True
                End If


                intCtr += 1
            Next
            dsPermission.Dispose()

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Function isLoaded(ByVal strFormName As String, Optional ByVal strTag As String = "") As Boolean
        isLoaded = False
        For Each frmchild As Form In Me.MdiChildren
            If Not (frmchild.Tag Is Nothing) Then
                If frmchild.Name.ToString = strFormName And frmchild.Tag.ToString = strTag Then
                    isLoaded = True : frmchild.BringToFront() : Exit Function
                End If
            ElseIf frmchild.Tag Is Nothing Or frmchild.Tag = String.Empty Then
                If frmchild.Name.ToString = strFormName And strTag = String.Empty Then
                    isLoaded = True : frmchild.BringToFront() : Exit Function
                End If
            End If
        Next
    End Function

    Private Function GetTaskbarLocation() As AlertFormLocation
        Dim tbwnd As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
        If tbwnd = IntPtr.Zero Then
            Return AlertFormLocation.BottomRight
        End If
        Dim abd As New AppBarData()
        abd.cbSize = Marshal.SizeOf(GetType(AppBarData))
        abd.hWnd = tbwnd
        Dim ptr As IntPtr = Marshal.AllocHGlobal(abd.cbSize)
        Try
            Marshal.StructureToPtr(abd, ptr, False)
            SHAppBarMessage(5, ptr)
            abd = CType(Marshal.PtrToStructure(ptr, GetType(AppBarData)), AppBarData)
        Finally
            Marshal.FreeHGlobal(ptr)
        End Try
        Return GetPosition(abd.rc)
    End Function

    Private Function GetPosition(ByVal rect As Rect) As AlertFormLocation
        If rect.top = rect.left AndAlso rect.bottom > rect.right Then
            Return AlertFormLocation.BottomLeft
        End If
        If rect.top = rect.left AndAlso rect.bottom < rect.right Then
            Return AlertFormLocation.TopRight
        End If
        Return AlertFormLocation.BottomRight
    End Function

    Private Sub mnuDefaultPath_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDefaultPath.ItemClick
        Dim strTemp As String

        Try

            strTemp = strRecordID("utility_document_path", "path", "path is not null")
            strTemp = InputBox("Specify Document Path", "Document Path", IIf(strTemp = "Null", "", strTemp))

            If strTemp <> "" Then
                If Directory.Exists(strTemp) = False Then
                    MessageBox.Show("Invalid document path!", gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
                Else
                    If Val(strRecordID("utility_document_path", "1", "path is not null")) = 0 Then
                        Call InsertintoTable("utility_document_path", "'" & Replace(strTemp, "'", "''") & "'")
                    Else
                        Call UpdateTable("utility_document_path", "path='" & Replace(strTemp, "'", "''") & "'")
                    End If
                    gstrDocumentPath = strRecordID("utility_document_path", "path", "path is not null")
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Dim intMin As Integer = 0
    Private Sub timerDateTime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerDateTime.Tick
        If gblnTimerTick = True Then
            mnuUserLogin.Caption = "User Loged In - " & gstrUserName
            mnuCurrentDate.Caption = Now.ToShortDateString
            mnuCurrentTime.Caption = Now.ToShortTimeString
            mnuCapsLock.Caption = "CAPS LOCK: " & IIf(My.Computer.Keyboard.CapsLock = True, "ON", "OFF")
            mnuNumLock.Caption = "NUM LOCK: " & IIf(My.Computer.Keyboard.NumLock = True, "ON", "OFF")

            intMin = intMin + 1
            If intMin = 10 Then
                If gconWebPlusMed.State = ConnectionState.Open Then
                    Call PopupAlert()
                    intMin = 0
                End If
            End If
        End If
    End Sub
    Dim info1 As AlertInfo
    Private Sub PopupAlert()
        Dim blnIsTransactionOpen As Boolean
        Try
            Dim dsTemp As DataSet
            dsTemp = FillDataSet("SELECT MessageId,SenderId,ReceiverId,Message,FullName as Sender,MessageDate  FROM tblMessages  JOIN vwUserDetails ON SenderId=UserId WHERE Acknowledgement=0 AND ReceiverId=" & gintUserID)

            For Each dr As DataRow In dsTemp.Tables(0).Rows

                If dsTemp.Tables(0).Rows.Count > 0 Then
                    Dim info As New AlertInfo("From: " & dr.Item("Sender") & " On: " & Format(dr.Item("MessageDate"), gstrDtFormat & " hh:mm tt"), dr.Item("Message"))
                    'info.Tag = "From: " & dr.Item("Sender")
                    info.Tag = dr.Item("SenderId")
                    alertCtrlMsg.FormLocation = GetTaskbarLocation()
                    alertCtrlMsg.Show(Me, info)
                    'alertCtrlMsg.a
                    gtrnWebPlusMed = gconWebPlusMed.BeginTransaction
                    blnIsTransactionOpen = True
                    Call UpdateTable("tblMessages", "Acknowledgement=1", "MessageId=" & dr.Item("MessageId"))
                    gtrnWebPlusMed.Commit()
                    blnIsTransactionOpen = False
                End If
            Next
            dsTemp.Dispose()

            dsTemp = FillDataSet("select tblVisits.VisitId,tblVisits.AppointmentTypeId,tblPatientInfo.FirstName + IsNull(' ' + tblPatientInfo.MiddleName,'') + IsNull(' ' + tblPatientInfo.LastName,'') [PatientName] from tblVisits,tblPatientInfo where tblPatientInfo.PatientId=tblVisits.PatientId and tblVisits.PracticeId=" & GetPracticeId(gintUserID) & " and tblVisits.AppointmentTypeId=3 and tblVisits.VisitStatus=0")
            For Each dr As DataRow In dsTemp.Tables(0).Rows
                If dsTemp.Tables(0).Rows.Count > 0 Then
                    'Dim info As New AlertInfo("Emergency", "Emergency Patient")
                    info1 = New AlertInfo("Emergency Patient", "Patient Name: " & dr.Item("PatientName"))
                    info1.Tag = dr.Item("VisitId")
                    alertctrlEmergency.FormLocation = GetTaskbarLocation()
                    alertctrlEmergency.Show(Me, info1)
                    'alertctrlEmergency.Buttons.PinButton.SetDown(True)
                    'gtrnWebPlusMed = gconWebPlusMed.BeginTransaction
                    'blnIsTransactionOpen = True

                    Call UpdateTable("tblVisits", "VisitStatus=1", "VisitId=" & dr.Item("VisitId"))
                    'gtrnWebPlusMed.Commit()
                    'blnIsTransactionOpen = False
                End If
            Next

        Catch ex As Exception
            If blnIsTransactionOpen = True Then
                gtrnWebPlusMed.Rollback()
            End If
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of mdlAllFunctions")
        End Try
    End Sub

    Private Sub mnuLogOut_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuLogOut.ItemClick
        If gstrUserName <> "p" Then
            Call UpdateTable("utility_user_login_details", "logout_time='" & gdtCurrentDate & "'", "record_id=" & glngLoginHistoryID)
        End If
        mblnLogOut = True
        Me.Dispose()
        Application.Restart()
    End Sub

    Private Sub mnuExit_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuExit.ItemClick
        Me.Close()
    End Sub

    Private Sub mnuLookupValues_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuLookupValues.ItemClick
        If isLoaded("frmToolsLookUp", "") Then Exit Sub
        Dim frmTempToolsLookUps As New frmToolsLookUp
        LoadCursor(Me)
        With frmTempToolsLookUps
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuSpecialistInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuSpecialistInformation.ItemClick
        If isLoaded("frmSpecialist", "") Then Exit Sub
        Dim frmTempSpecialist As New frmSpecialist
        LoadCursor(Me)
        With frmTempSpecialist
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPracticeInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPracticeInformation.ItemClick
        If isLoaded("frmPracticeInformation", "") Then Exit Sub
        Dim frmTempPracticeInformation As New frmPracticeInformation
        LoadCursor(Me)
        With frmTempPracticeInformation
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuTasks_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuTasks.ItemClick
        If isLoaded("frmTask", "") Then Exit Sub
        Dim frmTempTask As New frmTask
        LoadCursor(Me)
        With frmTempTask
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuDrugInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDrugInformation.ItemClick
        If isLoaded("frmDrugDetails", "") Then Exit Sub
        Dim frmTempDrugDetails As New frmDrugDetails
        LoadCursor(Me)
        With frmTempDrugDetails
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuInstantMessaging_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuInstantMessaging.ItemClick, mnuMessaging.ItemClick
        If isLoaded("frmMessages", "") Then Exit Sub
        Dim frmTempMessages As New frmMessages
        LoadCursor(Me)
        With frmTempMessages
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
        'Test.Show()
    End Sub

    Private Sub alertCtrlMsg_AlertClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Alerter.AlertClickEventArgs) Handles alertCtrlMsg.AlertClick
        If isLoaded("frmMessages", "") Then Exit Sub
        Dim frmTempMessages As New frmMessages
        LoadCursor(Me)
        With frmTempMessages
            .MdiParent = Me.ParentForm
            .mblnCheck = True
            .mintSenderID = CType(e.Info.Tag, Integer)
            .Show()
        End With
        DestroyCrushor(Me)
        e.AlertForm.Close()
        frmTempMessages.Focus()
    End Sub

    Private Sub mnuLockApplication_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuLockApplication.ItemClick
        If gblnLockPermission = False Then
            'Lock Application
            gblnLockPermission = True
            Me.WindowState = FormWindowState.Minimized
        Else
            'Unlock Application
            gblnLockPermission = False
        End If
    End Sub

    Private Sub mnuTbAppointments_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuTbAppointments.ItemClick
        If isLoaded("frmAppointmentEntry", "") Then Exit Sub
        Dim frmTempAppointmentEntry As New frmAppointmentEntry
        LoadCursor(Me)
        With frmTempAppointmentEntry
            .stDate = Format(Today, gstrDtFormat)

            '.MdiParent = Me
            .ShowInTaskbar = False
            .ShowDialog()
        End With
        DestroyCrushor(Me)
    End Sub

    'Private Sub mnuImportDrug_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuImportDrug.ItemClick
    '    Dim frmTempImportDrug As New frmImportDrug
    '    LoadCursor(Me)
    '    With frmTempImportDrug
    '        .MdiParent = Me
    '        .Show()
    '    End With
    '    DestroyCrushor(Me)
    'End Sub

    Public Sub mnuNursesNote_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuNursesNote.ItemClick
        If isLoaded("frmPatientStatus", "") Then Exit Sub
        Dim frmTempPatientStatus As New frmPatientStatus(PatientStatus.AwaitingNurse)
        LoadCursor(Me)
        With frmTempPatientStatus
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Public Sub mnuChangePatientStatus_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuChangePatientStatus.ItemClick
        If isLoaded("frmPatientStatus", "") Then Exit Sub
        Dim frmTempPatientStatus As New frmPatientStatus()
        LoadCursor(Me)
        With frmTempPatientStatus
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Public Sub mnuDoctorsNote_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDoctorsNote.ItemClick
        If isLoaded("frmPatientStatus", "") Then Exit Sub
        Dim frmTempPatientStatus As New frmPatientStatus(PatientStatus.AwaitingDoctor)
        LoadCursor(Me)
        With frmTempPatientStatus
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPatientInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPatientInformation.ItemClick
        If isLoaded("frmPatientInfo", "") Then Exit Sub
        Dim frmTempPatientInfo As New frmPatientInfo(-1)
        LoadCursor(Me)
        With frmTempPatientInfo
            .MdiParent = Me
            .Show()
            .btnAdd_click(Nothing, Nothing)
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuSearchPatient_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuSearchPatient.ItemClick
        If isLoaded("frmPatientSearch", "") Then Exit Sub
        Dim frmTempPatientSearch As New frmPatientSearch
        LoadCursor(Me)
        With frmTempPatientSearch
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRegistrationWizard_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRegistrationWizard.ItemClick
        If isLoaded("frmRegistrationWizard", "") Then Exit Sub
        Dim frmTempRegistrationWizard As New frmRegistrationWizard
        LoadCursor(Me)
        With frmTempRegistrationWizard
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRegisterPatient_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRegisterPatient.ItemClick
        If isLoaded("frmRegistrationWizard", "") Then Exit Sub
        Dim frmTempRegistrationWizard As New frmRegistrationWizard
        LoadCursor(Me)
        With frmTempRegistrationWizard
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuSearch_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuSearch.ItemClick
        If isLoaded("frmPatientSearch", "") Then Exit Sub
        Dim frmTempPatientSearch As New frmPatientSearch
        LoadCursor(Me)
        With frmTempPatientSearch
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuAddNotes_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuAddNotes.ItemClick
        If gintUserLevelId = 1 OrElse gintUserLevelId = 2 Then
            mnuDoctorsNote_ItemClick(sender, e)
        End If

        If gintUserLevelId = 3 Then
            mnuNursesNote_ItemClick(sender, e)
        End If

        If gintUserLevelId = 4 Then
            mnuChangePatientStatus_ItemClick(sender, e)
        End If
    End Sub

    Private Sub mnuDrugs_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDrugs.ItemClick
        If isLoaded("frmDrugDetails", "") Then Exit Sub
        Dim frmTempDrugDetails As New frmDrugDetails
        LoadCursor(Me)
        With frmTempDrugDetails
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuSetAppointmentDayWise_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuSetAppointmentDayWise.ItemClick
        If isLoaded("frmSetAppointmentTime", "") Then Exit Sub
        Dim frmTempSetAppointmentTime As New frmSetAppointmentTime
        LoadCursor(Me)
        With frmTempSetAppointmentTime
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub
    Private Sub mnuVisitSummary_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuVisitSummary.ItemClick
        Try
            Dim intPatientId As Integer
            Dim SingleClickOnGridExit As Boolean = True
            Dim SearchPatient As New frmPatientSearch(SingleClickOnGridExit)
            SearchPatient.ShowInTaskbar = False
            If SearchPatient.ShowDialog() = DialogResult.Cancel Then
                Exit Sub
            End If
            intPatientId = SearchPatient.PatientIdForAppointment

            Call ShowVisitSummaryReport(intPatientId, Me)
        Catch ex As Exception
            DestroyCrushor(Me)
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                 Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub mnuChargesPayment_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuChargesPayment.ItemClick
        If isLoaded("frmPatientStatus", "") Then Exit Sub
        Dim frmTempPatientStatus As New frmPatientStatus(PatientStatus.SeenByDoctor)
        LoadCursor(Me)
        With frmTempPatientStatus
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuInvoiceReport_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuInvoiceReport.ItemClick
        If isLoaded("frmSelectPatient", "InvoiceReport") Then Exit Sub
        Dim frmTempSelectPatient As New frmSelectPatient("Invoice")
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "InvoiceReport"
            .Show()
        End With
    End Sub

    Private Sub mnuReceiptReport_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuReceiptReport.ItemClick
        If isLoaded("frmSelectPatient", "ReceiptReport") Then Exit Sub
        Dim frmTempSelectPatient As New frmSelectPatient("Receipt")
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "ReceiptReport"
            .Show()
        End With
    End Sub

    Private Sub mnuOutstandingBalanceReport_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuOutstandingBalanceReport.ItemClick
        Call ShowOutStandingBalanceReport(Me)
    End Sub

    Private Sub mnuUpdateCheckStatus_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuUpdateCheckStatus.ItemClick
        If isLoaded("frmClearCheck", "") Then Exit Sub
        Dim frmTempClearCheck As New frmClearCheck
        LoadCursor(Me)
        With frmTempClearCheck
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuImportDrug_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuImportDrug.ItemClick
        If isLoaded("frmImportDrug", "") Then Exit Sub
        Dim frmTempImportDrug As New frmImportDrug()
        LoadCursor(Me)
        With frmTempImportDrug
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuBloodPressureGraph_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuBloodPressureGraph.ItemClick
        Dim SingleClickOnGridExit As Boolean = True

        Dim SearchPatient As New frmPatientSearch(SingleClickOnGridExit)
        SearchPatient.ShowInTaskbar = False
        If SearchPatient.ShowDialog() = DialogResult.Cancel Then
            Exit Sub
        End If

        ShowBloodPressureGraph(SearchPatient.PatientIdForAppointment, Me)
    End Sub

    Private Sub mnuVisitDetails_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuVisitDetails.ItemClick
        If isLoaded("frmSelectPatient", "VisitDetailsReport") Then Exit Sub
        Dim frmTempSelectPatient As New frmSelectPatient("Visit Details")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Visit Details"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPatientProfile_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPatientProfile.ItemClick
        If isLoaded("frmSelectPatient", "Patient's Profile") Then Exit Sub
        Dim frmTempSelectPatient As New frmSelectPatient("Patient's Profile")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Patient's Profile"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPatientStatement_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPatientStatement.ItemClick
        If isLoaded("frmPatientStatement", "Patient Statement") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Patient Statement")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Patient Statement"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuLengthForAge_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuLengthForAge.ItemClick
        If isLoaded("frmPatientStatement", "Length for Age") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Length for Age")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Length for Age"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuWeightFor36Age_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuWeightFor36Age.ItemClick
        If isLoaded("frmPatientStatement", "Weight for Age") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Weight for Age")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Weight for Age"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuHeadCirAge_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuHeadCirAge.ItemClick
        If isLoaded("frmPatientStatement", "Head Circumference for Age") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Head Circumference for Age")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Head Circumference for Age"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuDrugUseFrequency_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDrugUseFrequency.ItemClick
        If isLoaded("frmPracticeStatisticCharts", "") Then Exit Sub
        Dim frmTempPracticeStatisticCharts As New frmPracticeStatisticCharts()
        LoadCursor(Me)
        With frmTempPracticeStatisticCharts
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuWaitingPatients_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuWaitingPatients.ItemClick
        Call ShowPatientWaitingReport(Me)
    End Sub

    Private Sub mnuDaysPatients_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDaysPatients.ItemClick
        If isLoaded("frmDaysPatient", "") Then Exit Sub
        Dim frmTempDaysPatient As New frmDaysPatient()
        LoadCursor(Me)
        With frmTempDaysPatient
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuAddressBook_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuAddressBook.ItemClick
        If isLoaded("frmAddressBook", "") Then Exit Sub
        Dim frmTempAddressBook As New frmAddressBook()
        LoadCursor(Me)
        With frmTempAddressBook
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuReportsIcon_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuReportsIcon.ItemClick
        If isLoaded("frmSelectReport", "") Then Exit Sub
        Dim frmTempSelectReport As New frmSelectReport()
        LoadCursor(Me)
        With frmTempSelectReport
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Public Sub GetReportNode(ByRef lstReport As TreeList)
        Try
            lstReport.BeginUpdate()
            Dim parentNode As TreeListNode = Nothing
            Dim parentForRootNode As TreeListNode = lstReport.AppendNode(New Object() {"Reports"}, parentNode)
            If mnuOutstandingBalanceReport.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Outstanding Balance"}, parentForRootNode)
                rootNode1.Tag = mnuOutstandingBalanceReport
            End If
            If mnuPatientStatement.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Patient Statement"}, parentForRootNode)
                rootNode1.Tag = mnuPatientStatement
            End If
            If mnuVisitSummary.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Visit Summary"}, parentForRootNode)
                rootNode1.Tag = mnuVisitSummary
            End If

            If mnuVisitDetails.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Visit Details"}, parentForRootNode)
                rootNode1.Tag = mnuVisitDetails
            End If

            If mnuPatientProfile.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Patient Profile"}, parentForRootNode)
                rootNode1.Tag = mnuPatientProfile
            End If

            If mnuBloodPressureGraph.Enabled = True Then
                Dim rootNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Blood Pressure Graph"}, parentForRootNode)
                rootNode1.Tag = mnuBloodPressureGraph
            End If

            Dim rootNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Growth Chart"}, parentForRootNode)
            'rootNode2.Tag = mnuGrowthChart
            If mnuLengthForAge.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Length for Age"}, rootNode2)
                subNode1.Tag = mnuLengthForAge
            End If
            If mnuWeightFor36Age.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Weight For Age (Birth to 36 months)"}, rootNode2)
                subNode1.Tag = mnuWeightFor36Age
            End If
            If mnuHeadCirAge.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Head Circumefrence For Age"}, rootNode2)
                subNode1.Tag = mnuHeadCirAge
            End If
            If mnuWeightForLength.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Weight For Length"}, rootNode2)
                subNode1.Tag = mnuWeightForLength
            End If
            If mnuStatureForLength.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Stature For Length"}, rootNode2)
                subNode1.Tag = mnuStatureForLength
            End If
            If mnuWeightFor20Age.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Weight For Age (2 to 20 years)"}, rootNode2)
                subNode1.Tag = mnuWeightFor20Age
            End If
            If mnuBMIForAge.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"BMI For Age"}, rootNode2)
                subNode1.Tag = mnuBMIForAge
            End If
            If mnuWeightForStature.Enabled = True Then
                Dim subNode1 As TreeListNode = lstReport.AppendNode(New Object() {"Weight For Stature"}, rootNode2)
                subNode1.Tag = mnuWeightForStature
            End If

            Dim rootNode3 As TreeListNode = lstReport.AppendNode(New Object() {"Practice Statistic"}, parentForRootNode)
            If mnuDiagnosisFrequency.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Diagnosis Frequency"}, rootNode3)
                subNode2.Tag = mnuDiagnosisFrequency
            End If
            If mnuDiagnosisFrequencyAge.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Diagnosis Frequency (VS Age Group)"}, rootNode3)
                subNode2.Tag = mnuDiagnosisFrequencyAge
            End If
            If mnuDrugUseFrequency.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Drug Use Frequency"}, rootNode3)
                subNode2.Tag = mnuDrugUseFrequency
            End If
            If mnuNoofPatientsSeen.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"No of Patients Seen"}, rootNode3)
                subNode2.Tag = mnuNoofPatientsSeen
            End If
            If mnuCauseofDeath.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Cause of Death"}, rootNode3)
                subNode2.Tag = mnuCauseofDeath
            End If

            If mnuDaysPatients.Enabled = True Then
                Dim rootNode4 As TreeListNode = lstReport.AppendNode(New Object() {"Day's Patients"}, parentForRootNode)
                rootNode4.Tag = mnuDaysPatients
            End If

            If mnuWaitingPatients.Enabled = True Then
                Dim rootNode5 As TreeListNode = lstReport.AppendNode(New Object() {"Waiting Patients"}, parentForRootNode)
                rootNode5.Tag = mnuWaitingPatients
            End If

            If mnuAddressBook.Enabled = True Then
                Dim rootNode6 As TreeListNode = lstReport.AppendNode(New Object() {"Address Book"}, parentForRootNode)
                rootNode6.Tag = mnuAddressBook
            End If

            Dim rootNode7 As TreeListNode = lstReport.AppendNode(New Object() {"Financial Reports"}, parentForRootNode)
            If mnuRevenueByDate.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Revenue By Date"}, rootNode7)
                subNode2.Tag = mnuRevenueByDate
            End If
            If mnuRevenueByMonth.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Revenue By Month"}, rootNode7)
                subNode2.Tag = mnuRevenueByMonth
            End If
            If mnuRevenueByDiagnosis.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Revenue By Diagnosis"}, rootNode7)
                subNode2.Tag = mnuRevenueByDiagnosis
            End If
            If mnuRevenueByDemographics.Enabled = True Then
                Dim subNode2 As TreeListNode = lstReport.AppendNode(New Object() {"Revenue By Demographics"}, rootNode7)
                subNode2.Tag = mnuRevenueByDemographics
            End If

            lstReport.EndUpdate()
        Catch ex As Exception
            MessageBox.Show(ex.Message, gstrMessage, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                 Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub mnuLockApp_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuLockApp.ItemClick
        mnuLockApplication_ItemClick(Nothing, Nothing)
    End Sub

    Private Sub mnuExitApplication_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuExitApplication.ItemClick
        Application.Exit()
    End Sub

    Private Sub tmrRefresh_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrRefresh.Tick
        Try
            'Dim strRefresh As String = ""
            'Dim blnRefreshed As Boolean = False
            If gblnTimerTick = False Then Exit Sub
            If gblnIsRefreshed = False Then
                Exit Sub
            End If
            objAppointments.RefreshData("All")
            gblnIsRefreshed = False

            'strRefresh = strRecordID("Refresh_Dashboard", "IsRefreshAppt", "IsRefreshAppt is not null")

            'blnRefreshed = IIf(strRefresh = "True", True, False)
            'If blnRefreshed = True Then
            '    If Not objAppointments Is Nothing Then
            '        objAppointments.RefreshData("Appointments")
            '    End If
            '    blnRefreshed = False
            '    Call UpdateTable("Refresh_Dashboard", "IsRefreshAppt='false'")
            'End If

            'strRefresh = strRecordID("Refresh_Dashboard", "IsRefreshVisit", "IsRefreshVisit is not null")

            'blnRefreshed = IIf(strRefresh = "True", True, False)
            'If blnRefreshed = True Then
            '    If Not objAppointments Is Nothing Then
            '        objAppointments.RefreshData("Visits")
            '    End If
            '    blnRefreshed = False
            '    Call UpdateTable("Refresh_Dashboard", "IsRefreshVisit='false'")
            'End If

            'strRefresh = strRecordID("Refresh_Dashboard", "IsRefreshTask", "IsRefreshTask is not null")
            'blnRefreshed = IIf(strRefresh = "True", True, False)
            'If blnRefreshed = True Then
            '    If Not objAppointments Is Nothing Then
            '        objAppointments.RefreshData("Tasks")
            '    End If
            '    Call UpdateTable("Refresh_Dashboard", "IsRefreshTask='false'")
            '    blnRefreshed = False
            'End If

            'strRefresh = strRecordID("Refresh_Dashboard", "IsRefreshMessage", "IsRefreshMessage is not null")
            'blnRefreshed = IIf(strRefresh = "True", True, False)
            'If blnRefreshed = True Then
            '    If Not objAppointments Is Nothing Then
            '        objAppointments.RefreshData("Messages")
            '    End If
            '    Call UpdateTable("Refresh_Dashboard", "IsRefreshMessage='false'")
            '    blnRefreshed = False
            'End If

        Catch ex As Exception
            Call AddErrorLog("Error " & Err.Number & " (" & Err.Description & ") in Procedure " & _
                Reflection.MethodBase.GetCurrentMethod.Name & " Of " & Me.Name)
        End Try
    End Sub

    Private Sub mnuCascade_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuCascade.ItemClick
        'cascade windows
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub mnuTileHorizontally_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuTileHorizontally.ItemClick
        'tile windows horizontally
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub mnuTileVertically_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuTileVertically.ItemClick
        'tile windows vertically
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub mnuFileLogout_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuFileLogout.ItemClick
        Call mnuLogOut_ItemClick(Nothing, Nothing)
    End Sub

    Private Sub mnuProcedures_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuProcedures.ItemClick
        If isLoaded("frmProcedures", "") Then Exit Sub
        Dim frmTempProcedures As New frmProcedures()
        LoadCursor(Me)
        With frmTempProcedures
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub


    Private Sub mnuWeightFor20Age_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuWeightFor20Age.ItemClick
        If isLoaded("frmPatientStatement", "Weight for Age 2 To 20") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Weight for Age 2 To 20")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Weight for Age 2 To 20"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub alertctrlEmergency_FormLoad(ByVal sender As Object, ByVal e As DevExpress.XtraBars.Alerter.AlertFormLoadEventArgs) Handles alertctrlEmergency.FormLoad
        e.Buttons.PinButton.SetDown(True)

    End Sub

    Private Sub mnuWeightForLength_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuWeightForLength.ItemClick
        If isLoaded("frmPatientStatement", "Weight for Length") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("Weight for Length")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "Weight for Length"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuNoofPatientsSeen_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuNoofPatientsSeen.ItemClick
        If isLoaded("frmNoOfPatientSeen", "") Then Exit Sub
        Dim frmTempNoOfPatientSeen As New frmNoOfPatientSeen
        LoadCursor(Me)
        With frmTempNoOfPatientSeen
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuCauseofDeath_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuCauseofDeath.ItemClick
        If isLoaded("frmCauseOfDeathStatistics", "") Then Exit Sub
        Dim frmTempCauseOfDeathStatistics As New frmCauseOfDeathStatistics
        LoadCursor(Me)
        With frmTempCauseOfDeathStatistics
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRevenueByDate_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRevenueByDate.ItemClick
        If isLoaded("frmRevenueReport", "Revenue By Date") Then Exit Sub
        Dim frmTempRevenueReport As New frmRevenueReport("Revenue By Date")
        LoadCursor(Me)
        With frmTempRevenueReport
            .MdiParent = Me
            .Tag = "Revenue By Date"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuDiagnosisFrequency_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuDiagnosisFrequency.ItemClick
        If isLoaded("frmDiagnosisFrequency", "Diagnosis Frequency") Then Exit Sub
        Dim frmTempDiagnosisFrequency As New frmDiagnosisFrequency("Diagnosis Frequency")
        LoadCursor(Me)
        With frmTempDiagnosisFrequency
            .MdiParent = Me
            .Tag = "Diagnosis Frequency"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub
    Private Sub mnuRevenueByDiagnosis_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRevenueByDiagnosis.ItemClick
        If isLoaded("frmDiagnosisFrequency", "Revenue By Diagnosis") Then Exit Sub
        Dim frmTempDiagnosisFrequency As New frmDiagnosisFrequency("Revenue By Diagnosis")
        LoadCursor(Me)
        With frmTempDiagnosisFrequency
            .MdiParent = Me
            .Tag = "Revenue By Diagnosis"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRevenueByDemographics_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRevenueByDemographics.ItemClick
        If isLoaded("frmDiagnosisFrequency", "Revenue By Demographics") Then Exit Sub
        Dim frmTempDiagnosisFrequency As New frmDiagnosisFrequency("Revenue By Demographics")
        LoadCursor(Me)
        With frmTempDiagnosisFrequency
            .MdiParent = Me
            .Tag = "Revenue By Demographics"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuBMIForAge_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuBMIForAge.ItemClick
        If isLoaded("frmPatientStatement", "BMI For Age") Then Exit Sub
        Dim frmTempSelectPatient As New frmPatientStatement("BMI For Age")
        LoadCursor(Me)
        With frmTempSelectPatient
            .MdiParent = Me
            .Tag = "BMI For Age"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuMedicalVocabulary_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuMedicalVocabulary.ItemClick
        If isLoaded("frmMedicalVocabulary", "") Then Exit Sub
        Dim frmTempMedicalVocabulary As New frmMedicalVocabulary
        LoadCursor(Me)
        With frmTempMedicalVocabulary
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuReplicationImportData_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuReplicationImportData.ItemClick
        'LoadCursor(Me)
        'Call InsertDataFromXML()
        'DestroyCrushor(Me)
    End Sub

    Private Sub mnuVendorInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuVendorInformation.ItemClick
        If isLoaded("frmVendor", "") Then Exit Sub
        Dim frmTempVendor As New frmVendor
        LoadCursor(Me)
        With frmTempVendor
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuUnitDetails_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuUnitDetails.ItemClick
        If isLoaded("frmInventoryLookup", "Units") Then Exit Sub
        Dim frmTempInventoryLookup As New frmInventoryLookup
        LoadCursor(Me)
        With frmTempInventoryLookup
            .MdiParent = Me
            .Tag = "Units"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuCategoryDetails_ItemClick(ByVal sender As Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuCategoryDetails.ItemClick
        If isLoaded("frmInventoryLookup", "Category") Then Exit Sub
        Dim frmTempInventoryLookup As New frmInventoryLookup
        LoadCursor(Me)
        With frmTempInventoryLookup
            .MdiParent = Me
            .Tag = "Category"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuManufacturerInformation_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuManufacturerInformation.ItemClick
        If isLoaded("frmManufacturer", "") Then Exit Sub
        Dim frmTempManufacturer As New frmManufacturer
        LoadCursor(Me)
        With frmTempManufacturer
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuItemDetails_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuItemDetails.ItemClick
        If isLoaded("frmItemDetails", "") Then Exit Sub
        Dim frmTempItemDetails As New frmItemDetails
        LoadCursor(Me)
        With frmTempItemDetails
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPurchaseDetails_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPurchaseDetails.ItemClick
        If isLoaded("frmPurchase", "") Then Exit Sub
        Dim frmTempPurchase As New frmPurchase
        LoadCursor(Me)
        With frmTempPurchase
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuFixedAssets_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuFixedAssets.ItemClick
        If isLoaded("frmFixedAssets", "") Then Exit Sub
        Dim frmTempFixedAssets As New frmFixedAssets
        LoadCursor(Me)
        With frmTempFixedAssets
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRptFixedAssetsInventory_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptFixedAssetsInventory.ItemClick
        Call ShowFixedAssetsInventoryReport(Me)
    End Sub

    Private Sub mnuRptFixedAssetListing_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptFixedAssetListing.ItemClick
        Call ShowFixedAssetListingReport(Me)
    End Sub

    Private Sub mnuRptVendorListing_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptVendorListing.ItemClick
        If isLoaded("frmRptVendorListing", "") Then Exit Sub
        Dim frmTempVendorListing As New frmRptVendorListing()
        LoadCursor(Me)
        With frmTempVendorListing
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRptItemstobeReorder_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptItemstobeReorder.ItemClick
        If isLoaded("frmRptItemsReorder", "") Then Exit Sub
        Dim frmTempItemsReorder As New frmRptItemsReorder()
        LoadCursor(Me)
        With frmTempItemsReorder
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRptOnHandInventory_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptOnHandInventory.ItemClick
        If isLoaded("frmRptOnHandInventory", "") Then Exit Sub
        Dim frmTempOnHandInventory As New frmRptOnHandInventory()
        LoadCursor(Me)
        With frmTempOnHandInventory
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuInventoryAdjustment_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuInventoryAdjustment.ItemClick
        If isLoaded("frmInventoryAdjustment", "") Then Exit Sub
        Dim frmTempInventoryAdjustment As New frmInventoryAdjustment
        LoadCursor(Me)
        With frmTempInventoryAdjustment
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRptInventoryActivity_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRptInventoryActivity.ItemClick
        If isLoaded("frmRptInventoryActivityReport", "") Then Exit Sub
        Dim frmTempInventoryActivityReport As New frmRptInventoryActivityReport
        LoadCursor(Me)
        With frmTempInventoryActivityReport
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuFixedAssetCategory_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuFixedAssetCategory.ItemClick
        If isLoaded("frmInventoryLookup", "Fixed Asset Category") Then Exit Sub
        Dim frmTempInventoryLookup As New frmInventoryLookup
        LoadCursor(Me)
        With frmTempInventoryLookup
            .MdiParent = Me
            .Tag = "Fixed Asset Category"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuRevenueByMonth_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuRevenueByMonth.ItemClick
        If isLoaded("frmRevenueReport", "Revenue By Month") Then Exit Sub
        Dim frmTempRevenueReport As New frmRevenueReport("Revenue By Month")
        LoadCursor(Me)
        With frmTempRevenueReport
            .MdiParent = Me
            .Tag = "Revenue By Month"
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuTask1_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuTask1.ItemClick
        If isLoaded("frmTask", "") Then Exit Sub
        Dim frmTempTask As New frmTask
        LoadCursor(Me)
        With frmTempTask
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

    Private Sub mnuPurchaseOrder_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles mnuPurchaseOrder.ItemClick
        If isLoaded("frmPurchaseOrder", "") Then Exit Sub
        LoadCursor(Me)
        Dim frmTempPurchaseOrder As New frmPurchaseOrder
        With frmTempPurchaseOrder
            .MdiParent = Me
            .Show()
        End With
        DestroyCrushor(Me)
    End Sub

End Class
